API: gdk: Add gdk_window_new_popup()
authorBenjamin Otte <otte@redhat.com>
Sun, 6 Nov 2016 22:47:56 +0000 (23:47 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 6 Nov 2016 22:47:56 +0000 (23:47 +0100)
... and use it.

docs/reference/gdk/gdk4-sections.txt
gdk/gdkwindow.c
gdk/gdkwindow.h
gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkdnd-wayland.c
gdk/win32/gdkdevicemanager-win32.c
gdk/x11/gdkdnd-x11.c
gtk/gtktreeview.c
gtk/gtkwindow.c
testsuite/gtk/defaultvalue.c
testsuite/gtk/notify.c

index 65d7e138f455efae9460cfa725b99179cd85a1a8..0d88611f55634c8362b2bd1784cc6a876728b74c 100644 (file)
@@ -279,6 +279,7 @@ GdkWindowAttr
 GdkWindowAttributesType
 gdk_window_new
 gdk_window_new_toplevel
+gdk_window_new_popup
 gdk_window_new_child
 gdk_window_new_input
 gdk_window_destroy
index 846174c99126b77f94e3e53a349e2ccf9de74531..0d7a6d6f850e62d17fb05f9482b2812262f1ffdd 100644 (file)
@@ -1330,6 +1330,41 @@ gdk_window_new_toplevel (GdkDisplay *display,
                          0);
 }
 
+/**
+ * gdk_window_new_popup: (constructor)
+ * @display: the display to create the window on
+ * @event_mask: event mask (see gdk_window_set_events())
+ * @position: position of the window on screen
+ *
+ * Creates a new toplevel popup window. The window will bypass window
+ * management.
+ *
+ * Returns: (transfer full): the new #GdkWindow
+ *
+ * Since: 3.90
+ **/
+GdkWindow *
+gdk_window_new_popup (GdkDisplay         *display,
+                      gint                event_mask,
+                      const GdkRectangle *position)
+{
+  GdkWindowAttr attr;
+
+  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+  g_return_val_if_fail (position != NULL, NULL);
+
+  attr.event_mask = event_mask;
+  attr.wclass = GDK_INPUT_OUTPUT;
+  attr.x = position->x;
+  attr.y = position->y;
+  attr.width = position->width;
+  attr.height = position->height;
+  attr.window_type = GDK_WINDOW_TEMP;
+
+  return gdk_window_new (gdk_screen_get_root_window (gdk_display_get_default_screen (display)),
+                         &attr,
+                         GDK_WA_X | GDK_WA_Y);
+}
 /**
  * gdk_window_new_child: (constructor)
  * @parent: the parent window
index 960c16dd779badcd548d413ade4dd5c706d6293e..33c3d524088d50d232fbb0e19e5c3361a7cc59d9 100644 (file)
@@ -471,6 +471,10 @@ GdkWindow *   gdk_window_new_toplevel          (GdkDisplay    *display,
                                                 int            width,
                                                 int            height);
 GDK_AVAILABLE_IN_3_90
+GdkWindow *   gdk_window_new_popup             (GdkDisplay    *display,
+                                                gint           event_mask,
+                                                const GdkRectangle *position);
+GDK_AVAILABLE_IN_3_90
 GdkWindow *   gdk_window_new_child             (GdkWindow     *parent,
                                                 gint           event_mask,
                                                 const GdkRectangle *position);
index ce4915bea18cb9474b53a6de2094efcf2697b23f..45483af70592f373b6ee2bfdcf55a4c6a611266a 100644 (file)
@@ -4511,20 +4511,7 @@ static const struct wl_surface_listener pointer_surface_listener = {
 static GdkWindow *
 create_foreign_dnd_window (GdkDisplay *display)
 {
-  GdkWindowAttr attrs;
-  GdkScreen *screen;
-  guint mask;
-
-  screen = gdk_display_get_default_screen (display);
-
-  attrs.x = attrs.y = 0;
-  attrs.width = attrs.height = 1;
-  attrs.wclass = GDK_INPUT_OUTPUT;
-  attrs.window_type = GDK_WINDOW_TEMP;
-
-  mask = GDK_WA_X | GDK_WA_Y;
-
-  return gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask);
+  return gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 1, 1 });
 }
 
 static void
index ca5ec779fa0f9c295e6f6d9a430c486d0d3a9711..184c6a0b695dd01c4edb5cd7360b7598178ffe5a 100644 (file)
@@ -498,20 +498,11 @@ _gdk_wayland_window_register_dnd (GdkWindow *window)
 }
 
 static GdkWindow *
-create_dnd_window (GdkScreen *screen)
+create_dnd_window (GdkDisplay *display)
 {
-  GdkWindowAttr attrs;
   GdkWindow *window;
-  guint mask;
 
-  attrs.x = attrs.y = 0;
-  attrs.width = attrs.height = 100;
-  attrs.wclass = GDK_INPUT_OUTPUT;
-  attrs.window_type = GDK_WINDOW_TEMP;
-
-  mask = GDK_WA_X | GDK_WA_Y;
-
-  window = gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask);
+  window = gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 100, 100 });
 
   gdk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND);
   
@@ -538,7 +529,7 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
 
   gdk_drag_context_set_device (context, device);
 
-  context_wayland->dnd_window = create_dnd_window (gdk_window_get_screen (window));
+  context_wayland->dnd_window = create_dnd_window (gdk_window_get_display (window));
   context_wayland->dnd_surface = gdk_wayland_window_get_wl_surface (context_wayland->dnd_window);
   context_wayland->data_source =
     gdk_wayland_selection_get_data_source (window,
index 62c164d355437a1daf65909fbbd67f5b9c2ab9a0..7c8794ff59b822ba52b4259d0573a0dfb482761d 100644 (file)
@@ -354,7 +354,6 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager)
   GdkWindow *root = gdk_screen_get_root_window (gdk_display_get_default_screen (display));
   static gboolean wintab_initialized = FALSE;
   GdkDeviceWintab *device;
-  GdkWindowAttr wa;
   WORD specversion;
   HCTX *hctx;
   UINT ndevices, ncursors, ncsrtypes, firstcsr, hardware;
@@ -434,18 +433,7 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager)
                            ndevices, ncursors));
 #endif
   /* Create a dummy window to receive wintab events */
-  wa.wclass = GDK_INPUT_OUTPUT;
-  wa.event_mask = GDK_ALL_EVENTS_MASK;
-  wa.width = 2;
-  wa.height = 2;
-  wa.x = -100;
-  wa.y = -100;
-  wa.window_type = GDK_WINDOW_TOPLEVEL;
-  if ((wintab_window = gdk_window_new (root, &wa, GDK_WA_X | GDK_WA_Y)) == NULL)
-    {
-      g_warning ("gdk_input_wintab_init: gdk_window_new failed");
-      return;
-    }
+  wintab_window = gdk_window_new_popup (display, GDK_ALL_EVENTS_MASK, &(GdkRectangle) { -100, -100, 2, 2 });
   g_object_ref (wintab_window);
 
   for (devix = 0; devix < ndevices; devix++)
index f4cdcc33c31c4a61766ac3bc82a9160f8dee8021..ac5e51e8e59ab4b570d1987e8c753af8b655a158 100644 (file)
@@ -1991,20 +1991,11 @@ gdk_drag_do_leave (GdkX11DragContext *context_x11,
 }
 
 static GdkWindow *
-create_drag_window (GdkScreen *screen)
+create_drag_window (GdkDisplay *display)
 {
-  GdkWindowAttr attrs = { 0 };
   GdkWindow *window;
-  guint mask;
 
-  attrs.x = attrs.y = 0;
-  attrs.width = attrs.height = 100;
-  attrs.wclass = GDK_INPUT_OUTPUT;
-  attrs.window_type = GDK_WINDOW_TEMP;
-
-  mask = GDK_WA_X | GDK_WA_Y;
-
-  window = gdk_window_new (gdk_screen_get_root_window (screen), &attrs, mask);
+  window = gdk_window_new_popup (display, 0, &(GdkRectangle) { 0, 0, 100, 100 });
 
   gdk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND);
   
@@ -2037,7 +2028,7 @@ _gdk_x11_window_drag_begin (GdkWindow *window,
   GDK_X11_DRAG_CONTEXT (context)->start_x = x_root;
   GDK_X11_DRAG_CONTEXT (context)->start_y = y_root;
 
-  GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_screen (window));
+  GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_display(window));
 
   return context;
 }
index 9747b63d192467e0da34567c2cfdd32028271631..595d5720b44b0fed18282d9cdd340c92a1ef6225 100644 (file)
@@ -3938,25 +3938,15 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
       /* Create the new window */
       if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
        {
-          GdkWindowAttr attributes;
-          gint attributes_mask;
-
          if (tree_view->priv->drag_highlight_window)
            {
              gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
              gdk_window_destroy (tree_view->priv->drag_highlight_window);
            }
 
-         attributes.window_type = GDK_WINDOW_TEMP;
-         attributes.wclass = GDK_INPUT_OUTPUT;
-         attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK;
-         attributes_mask = GDK_WA_X | GDK_WA_Y;
-          attributes.x = x;
-          attributes.y = y;
-         attributes.width = width;
-         attributes.height = height;
-         tree_view->priv->drag_highlight_window = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)),
-                                                                  &attributes, attributes_mask);
+         tree_view->priv->drag_highlight_window = gdk_window_new_popup (gtk_widget_get_display (widget),
+                                                                         GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK,
+                                                                         &(GdkRectangle) { x, y, width, height });
          gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 
          mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
@@ -4017,24 +4007,15 @@ gtk_tree_view_motion_draw_column_motion_arrow (GtkTreeView *tree_view)
       if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
          tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
        {
-          GdkWindowAttr attributes;
-          gint attributes_mask;
-
          if (tree_view->priv->drag_highlight_window)
            {
              gtk_widget_unregister_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
              gdk_window_destroy (tree_view->priv->drag_highlight_window);
            }
 
-         attributes.window_type = GDK_WINDOW_TEMP;
-         attributes.wclass = GDK_INPUT_OUTPUT;
-         attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK;
-         attributes_mask = GDK_WA_X | GDK_WA_Y;
-          attributes.x = x;
-          attributes.y = y;
-         attributes.width = width;
-         attributes.height = height;
-         tree_view->priv->drag_highlight_window = gdk_window_new (gdk_screen_get_root_window (gtk_widget_get_screen (widget)), &attributes, attributes_mask);
+         tree_view->priv->drag_highlight_window = gdk_window_new_popup (gtk_widget_get_display (widget),
+                                                                         GDK_VISIBILITY_NOTIFY_MASK | GDK_POINTER_MOTION_MASK,
+                                                                         &(GdkRectangle) { x, y, width, height });
          gtk_widget_register_window (GTK_WIDGET (tree_view), tree_view->priv->drag_highlight_window);
 
          mask_image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
index 764cbf5ff7c8ddbc3194af6f9ed34f8a818a8150..28b68af93374265d464359615134a65740b45b9e 100644 (file)
@@ -6858,9 +6858,9 @@ gtk_window_realize (GtkWidget *widget)
   GtkAllocation child_allocation;
   GtkWindow *window;
   GdkWindow *gdk_window;
-  GdkWindowAttr attributes;
   GtkBorder window_border;
   GtkWindowPrivate *priv;
+  gint event_mask;
   gint i;
   GList *link;
 
@@ -6931,30 +6931,26 @@ gtk_window_realize (GtkWidget *widget)
     }
   else
     {
-      attributes.wclass = GDK_INPUT_OUTPUT;
-
       _gtk_widget_get_allocation (widget, &allocation);
-      attributes.width = allocation.width;
-      attributes.height = allocation.height;
-      attributes.event_mask = gtk_widget_get_events (widget);
-      attributes.event_mask |= (GDK_EXPOSURE_MASK |
-                                GDK_BUTTON_PRESS_MASK |
-                                GDK_BUTTON_RELEASE_MASK |
-                                GDK_BUTTON_MOTION_MASK |
-                                GDK_KEY_PRESS_MASK |
-                                GDK_KEY_RELEASE_MASK |
-                                GDK_ENTER_NOTIFY_MASK |
-                                GDK_LEAVE_NOTIFY_MASK |
-                                GDK_FOCUS_CHANGE_MASK |
-                                GDK_STRUCTURE_MASK);
+      event_mask = gtk_widget_get_events (widget);
+      event_mask |= (GDK_EXPOSURE_MASK |
+                     GDK_BUTTON_PRESS_MASK |
+                     GDK_BUTTON_RELEASE_MASK |
+                     GDK_BUTTON_MOTION_MASK |
+                     GDK_KEY_PRESS_MASK |
+                     GDK_KEY_RELEASE_MASK |
+                     GDK_ENTER_NOTIFY_MASK |
+                     GDK_LEAVE_NOTIFY_MASK |
+                     GDK_FOCUS_CHANGE_MASK |
+                     GDK_STRUCTURE_MASK);
       if (priv->decorated && priv->client_decorated)
-        attributes.event_mask |= GDK_POINTER_MOTION_MASK;
+        event_mask |= GDK_POINTER_MOTION_MASK;
 
       switch (priv->type)
         {
         case GTK_WINDOW_TOPLEVEL:
           gdk_window = gdk_window_new_toplevel (gtk_widget_get_display (widget),
-                                                attributes.event_mask,
+                                                event_mask,
                                                 allocation.width,
                                                 allocation.height);
           break;
@@ -6964,15 +6960,15 @@ gtk_window_realize (GtkWidget *widget)
               GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)))
             {
               gdk_window = gdk_wayland_window_new_subsurface (gtk_widget_get_display (widget),
-                                                              attributes.event_mask,
+                                                              event_mask,
                                                               &allocation);
             }
           else
 #endif
             {
-              attributes.window_type = GDK_WINDOW_TEMP;
-              gdk_window = gdk_window_new (gdk_screen_get_root_window (_gtk_window_get_screen (window)),
-                                           &attributes, 0);
+              gdk_window = gdk_window_new_popup (gtk_widget_get_display (widget),
+                                                 event_mask,
+                                                 &allocation);
             }
           break;
         default:
index 1c5cecbb7d1cf957a10dc85a6957b910ae8c43b9..8af8f4f0d23a7d432fdef8265f726931328e3d76 100644 (file)
@@ -107,13 +107,9 @@ test_type (gconstpointer data)
     instance = g_object_ref (gtk_settings_get_default ());
   else if (g_type_is_a (type, GDK_TYPE_WINDOW))
     {
-      GdkWindowAttr attributes;
-      attributes.wclass = GDK_INPUT_OUTPUT;
-      attributes.window_type = GDK_WINDOW_TEMP;
-      attributes.event_mask = 0;
-      attributes.width = 100;
-      attributes.height = 100;
-      instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
+      instance = g_object_ref (gdk_window_new_popup (gdk_display_get_default (),
+                                                     0,
+                                                     &(GdkRectangle) { 0, 0, 100, 100 }));
     }
   else if (g_str_equal (g_type_name (type), "GdkX11Cursor"))
     instance = g_object_new (type, "display", display, NULL);
index 65aba315b872b03b315084dd1f24df02934e9f3b..3f369136a6c2c86197f0dc8952508f834dbf6df8 100644 (file)
@@ -403,13 +403,9 @@ test_type (gconstpointer data)
     instance = g_object_ref (gtk_settings_get_default ());
   else if (g_type_is_a (type, GDK_TYPE_WINDOW))
     {
-      GdkWindowAttr attributes;
-      attributes.wclass = GDK_INPUT_OUTPUT;
-      attributes.window_type = GDK_WINDOW_TEMP;
-      attributes.event_mask = 0;
-      attributes.width = 100;
-      attributes.height = 100;
-      instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
+      instance = g_object_ref (gdk_window_new_popup (gdk_display_get_default (),
+                                                     0,
+                                                     &(GdkRectangle) { 0, 0, 100, 100 }));
     }
   else if (g_str_equal (g_type_name (type), "GdkX11Cursor"))
     instance = g_object_new (type, "display", display, NULL);